<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<%--
  Created by IntelliJ IDEA.
  User: 18134216985
  Date: 2024-04-22
  Time: 14:38
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="/webjars/layui/2.6.8/css/layui.css">
    <script src="/webjars/layui/2.6.8/layui.js"></script>
</head>
<body>
<%--条件查询--%>
<div class="layui-collapse">
    <div class="layui-colla-item">

        <h2 class="layui-colla-title">查询条件</h2>
        <div class="layui-colla-content layui-show">
            <div class="layui-form"  id="searchForm" lay-filter="searchForm">
                <div class="layui-inline">
                    <select name="seachitemid">
                        <option value="0">请选择缴费类型</option>
                    </select>
                </div>
                <div class="layui-inline">
                    <select name="paystate">
                        <option value="2">请选择支付状态</option>
                        <option value="0">未缴费</option>
                        <option value="1">已缴费</option>
                    </select>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn" onclick="search()" >查询</button>
                </div>
            </div>
        </div>
    </div>
</div>
<div id="add" style="display:none;padding:20px">

    <form class="layui-form" id="addForm" lay-filter="addForm">
        <div class="layui-form-item">
            <label class="layui-form-label">缴费类型:</label>
            <div class="layui-input-block">
                <select name="itemid">
                    <option value="0">请选择缴费项目</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">备注:</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" name="notes" class="layui-textarea"></textarea>
            </div>
        </div>
        <input type="hidden" name="owners">
        <table class="layui-hide" id="ID-ownertable-demo-data" lay-filter="ownerTable"></table>
    </form>
</div>
<div id="caradd" style="display:none;padding:20px">

    <form class="layui-form" id="caraddForm" lay-filter="caraddForm">
        <div class="layui-form-item">
            <label class="layui-form-label">备注:</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" name="notes" class="layui-textarea"></textarea>
            </div>
        </div>
        <input type="hidden" name="itemid" value="3">
        <input type="hidden" name="owners">
        <table class="layui-hide" id="ID-carownertable-demo-data" lay-filter="carownerTable"></table>
    </form>
</div>
<script type="text/html" id="headTool">
    <button class="layui-btn" onclick="add()">生成缴费</button>
    <button class="layui-btn" onclick="caradd()">车位管理缴费</button>
</script>
    <table class="layui-hide" id="ID-paytable-demo-data" lay-filter="payTable"></table>
<script>
    let $=layui.$
    let table=layui.table;
    $.get("/Item/selectItemOther").then(({data})=>{
        $(data).each(function (i,e){
            let option =$("<option value='"+e.id+"'>"+e.itemname+"</option>")
            $("[name=itemid]").append(option)
        })
        layui.form.render('select')
    })
    $.get("/tempPay/selectAllGuDingItem").then(({data})=>{
        $(data).each(function (i,e){
            let option =$("<option value='"+e.id+"'>"+e.itemname+"</option>")
            $("[name=seachitemid]").append(option)
        })
        layui.form.render('select')
    })
    layui.use(["table","laydate"],function (){
        table.render({
            id:'pay',
            elem:'#ID-paytable-demo-data',
            url:"/tempPay/selectAllPay",
            page:true,
            toolbar:"#headTool",
            cols:[[
                {field:'number',align: 'center',type:'numbers',title:"编号"},
                {field:'id',align: 'center',hide:true,title:"序号"},
                {align: 'center',field: 'ownerid',title: '业主',templet(d) {
                        return d.owners==null?"-":d.owners.ownername;
                    }},
                {align: 'center',field: 'itemid',title: '缴费项目',templet(d) {
                        return d.item==null?"-":d.item.itemname;
                    }},
                {align: 'center',field: 'paymoney',title: '支付金额'},
                {align: 'center',field: 'paytime=',title: '支付时间',templet(d){
                        return d.paytime==null?"-":d.paytime;
                    }},
                {align: 'center',field: 'createtime',title: '生成时间'},
                {align: 'center',field: 'paystate',title: '付款状态',templet(d) {
                        return d.paystate==0?"未支付":"已支付";
                    }},
                {align: 'center',field: 'notes',title: '备注'},
            ]]
        })

    })
    //点击查询
    function search(){
        var search=layui.form.val('searchForm');
        layui.table.reload('pay', {
            page: {
                curr:1
            },
            where: search
        });
    }
    function add(){
        var allowner;
        layui.use(["table","laydate"],function (){
            table.render({
                id:'owner',
                elem:'#ID-ownertable-demo-data',
                url:"/owner/selectAllOwners",
                page:true,
                cols:[[
                    {type: 'checkbox', fixed: 'left'},
                    {field:'number',align: 'center',type:'numbers',title:"编号"},
                    {field:'id',align: 'center',hide:true,title:"序号"},
                    {align: 'center',field: 'ownername',title: '业主姓名'},
                    {align: 'center',field: 'ownerphone',title: '联系方式'},
                    {align: 'center',field: 'ownersex',title: '性别'},
                    {align: 'center',field: 'plotid',title: '小区',templet(d){
                        return d.plot==null?"-":d.plot.plotname;
                        }},
                ]]
            })
            table.on('checkbox', function(obj){
                allowner = layui.table.checkStatus('owner').data;

            })
        })

            layui.layer.open({
                type:1,
                title:"添加",
                area:["700px","500px"],
                content:$("#add"),
                btn:["确定","取消"],
                yes(){
                    var ownerid=[];
                    $(allowner).each(function (i,e){
                         ownerid.push(e.id)
                    })
                    $("[name=owners]").val(ownerid)
                   let data=layui.form.val("addForm")
                    $.post("/tempPay/addPayPi",data).then(({msg})=>{
                        layui.layer.close(layui.layer.index);
                        layui.layer.msg(msg);
                        layui.table.reload("pay")
                    })
                }
            })
    }

/*-------------------------------------------------------*/
    function caradd(){
        var carallowner;
        layui.use(["table","laydate"],function (){
            table.render({
                id:'carowner',
                elem:'#ID-carownertable-demo-data',
                url:"/owner/selectHaveCar",
                page:true,
                cols:[[
                    {type: 'checkbox', fixed: 'left'},
                    {field:'number',align: 'center',type:'numbers',title:"编号"},
                    {field:'id',align: 'center',hide:true,title:"序号"},
                    {align: 'center',field: 'ownername',title: '业主姓名'},
                    {align: 'center',field: 'ownerphone',title: '联系方式'},
                    {align: 'center',field: 'ownersex',title: '性别'},
                    {align: 'center',field: 'plotid',title: '小区',templet(d){
                        console.log(d.plot)
                            return d.plot==null?"-":d.plot.plotname;
                        }},
                ]]
            })
            table.on('checkbox', function(obj){
                carallowner = layui.table.checkStatus('carowner').data;
            })
        })

        layui.layer.open({
            type:1,
            title:"添加",
            area:["700px","500px"],
            content:$("#caradd"),
            btn:["确定","取消"],
            yes(){
                var carownerid=[];
                $(carallowner).each(function (i,e){
                    carownerid.push(e.id)
                })
                $("[name=owners]").val(carownerid)
                let data=layui.form.val("caraddForm")
                console.log(data)
                $.post("/tempPay/addPayPi",data).then(({msg})=>{
                    layui.layer.close(layui.layer.index);
                    layui.layer.msg(msg);
                    layui.table.reload("pay")
                })
            }
        })
    }
</script>
</body>
</html>
